<?php

// 获取导航的公共方法   考虑二级导航的方法   获取某一组
use App\Server\Model\Content;
use App\Server\Model\Slide;

function getNavByGroupId($id){
    $navModel = new \App\Server\Model\Nav();
    $navlist = $navModel->getList([['nav_group_id','=',$id]],['*'],'sort asc');
    $navlist = list_to_tree($navlist);
    return $navlist??[];
}

// 获取当前导航id  定位
function getNowNavId(){
    return request()->query('nav_id');
}

// 获取单点配置的公共方法    缓存直接拿取
function getOneWebConfig($key){
    $webConfig = new \App\Server\Model\Webconfig();
    $where = [];
    $where[] = ['type','=',2];
    $webConfigList = $webConfig->getList($where,['*']);
    $webConfigList = array_column($webConfigList,null,'config_key');
    $oneRes = !empty($webConfigList[$key])?$webConfigList[$key]['config_value']:'';
    return $oneRes;
}

// 获取某一分类下的所有分类 自身和二级
function getAllCate($id){
    $cateModel = new \App\Server\Model\Cate();
    $cateInfo = $cateModel->getInfo([['id','=',$id]],'*');
    $cateIds = $cateModel->getPluck([['pid','=',$id]],'id');
    $cateIds[] = $id;
    return [$cateIds,$cateInfo];
}

// 获取文章列表的公共方法    指定分类  指定条数

function getContent($cate_id,$order = 'id desc'){
    list($cateIds,$cateInfo) = getAllCate($cate_id);
    $contentModel = new Content();
    $where = [];
    $where['whereIn'][] = ['cate_id',$cateIds];
    $getRes = $contentModel->getList($where,$field=['*'],$order);
    foreach ($getRes as &$v){
        $v['href'] = '/portal/portal/content_detail?id='.$v['id'];
    }
    return $getRes;
}

// 获取评论
function getContentComment($id,$order = 'id desc'){
    $contentCommentModel = new \App\Server\Model\ContentComment();
    $where = [];
    $where[] = ['content_id','=',$id];
    $getRes = $contentCommentModel->getList($where,$field=['*'],$order);
    return $getRes;
}

// 根据组获取轮播图
function getSlide($group_id,$order = 'id desc'){
    $slideModel = new Slide();
    $where = [];
    $where[]= ['slide_group_id','=',$group_id];
    $getRes = $slideModel->getList($where,['*'],$order);
    return $getRes;
}

// 判定数字是否是奇数偶数
function getNumType($num){
    if ($num%2==0){
        return true;
    }else{
        return false;
    }
}
